package com.xingjiejian.feature.lambda;

import com.xingjiejian.feature.lambda.pojo.Human;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * Lambda表达式增强版Comparator和集合排序
 * @author XingJiejian
 * @date 2019/5/6 0006
 */
public class Demo3 {

    public static void main(String[] args) {
        List<Human> humans = Arrays.asList(new Human("Sarah", 10), new Human("Jack", 12));
        //排序前
        System.out.println("====排序前====");
        humans.forEach(System.out::println);

        //Java8之前：
//        Collections.sort(humans, new Comparator<Human>() {
//            @Override
//            public int compare(Human h1, Human h2) {
//                return h1.getName().compareTo(h2.getName());
//            }
//        });

        //Java8之后
        Collections.sort(humans,(h1,h2)->h1.getName().compareTo(h2.getName()));


        //排序后
        System.out.println("====排序后====");
        humans.forEach(System.out::println);
    }
}

